from numpy.core import *

class Bar:
    pN=array([0.,0.])
    pM=array([0.,1.])
    first_index = 0
    second_index = 1
    A=1.
    E=1000000.
    L=1.
    sintheta=0.
    costheta=1.

    def set_nodes(self,pN,pM):
        self.pN=pN
        self.pM=pM
        pNmpM=pN-pM
        self.L=sqrt(sum(pNmpM*pNmpM))
        self.sintheta=pNmpM[1]/self.L
        self.costheta=pNmpM[0]/self.L

    def set_properties(self,A,E):
        self.A=A
        self.E=E
        
    def set_first_index(self,first_index):
        self.first_index=first_index

    def set_second_index(self,second_index):
        self.second_index=second_index

    def stiffness_matrix(self):
        k=self.A*self.E/self.L*\
            array([[1,0,-1,0],
                   [0,0,0,0],
                   [-1,0,1,0],
                   [0,0,0,0]],'d',order='C')
        c=array([[self.costheta,-self.sintheta,0,0],
                 [self.sintheta,self.costheta,0,0],
                 [0,0,self.costheta,-self.sintheta],
                 [0,0,self.sintheta,self.costheta]],
                'd',order='C')
        return dot(c,dot(k,transpose(c)))
